home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Programmer Disk
/
The Programmer Disk (Microforum).iso
/
xpro
/
pascal2
/
pro7
/
split.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-08-04
|
3KB
|
84 lines
{TITLE: Split file utility}
program Split;
const
RecSize = 128; {Default block read/write size}
BufSize = 384;
var
InFile, OutFile: File;
Buffer: array [1..RecSize, 1..BufSize] of byte;
InputSize, OutputSize, Count, i, RecsRead: integer;
Extension: string [3];
FileName: string [253]; {Enough space for a pathname}
label
8000, 8500, 8700, 9000;
{*********************************************************************}
{* Split reads a file (first parameter) of arbitrary size and writes *}
{* it out to one or more files (second parameter). The first output *}
{* file has the extension '.001'. A maximum of 48Kbytes are written *}
{* to the output file. When that size is reached the output file is *}
{* closed, the extension is incremented, and then the output file is *}
{* re-opened. Only the last file written will have a size other than *}
{* 49152 bytes. As each output file is closed, the name and size of *}
{* the file is written to the screen. When the end of the input file *}
{* is reached, the name and size of the input file is written to the *}
{* screen. This program is in the public domain. Written June 86 by *}
{* David G. Holm (Bix id 'dgh', Genie id 'DHOLM', Plink id 'OLS185') *}
{*********************************************************************}
begin
InputSize := 0;
OutputSize := 0;
if paramcount > 0 then begin
assign (InFile, paramstr (1));
reset (InFile);
if paramcount > 1 then begin
FileName := paramstr (2) + '.';
if pos ('.', FileName) < length (FileName)
then goto 8700;
Count := 1;
Extension := '001';
assign (OutFile, FileName + Extension);
rewrite (OutFile);
end
else goto 8500;
end
else goto 8000;
repeat {until eof...}
repeat {until OutputSize...}
blockread (InFile, Buffer, BufSize, RecsRead);
InputSize := InputSize + RecsRead;
blockwrite (OutFile, Buffer, RecsRead);
OutputSize := OutputSize + RecsRead;
until (OutputSize >= BufSize) or eof (InFile);
close (OutFile);
writeln (int (OutputSize) * int (RecSize):1:0, ' bytes written to ',
Filename, Extension, '.');
if not eof (InFile)
then begin
OutputSize := 0;
Count := Count + 1;
str (Count:3, Extension);
for i := 1 to 3 do
if Extension [i] = ' '
then Extension [i] := '0';
assign (OutFile, FileName + Extension);
rewrite (OutFile);
end;
until eof (InFile);
writeln (int (InputSize) * int (RecSize):1:0, ' bytes read from ',
paramstr(1), '.');
goto 9000;
8000:
writeln ('No input file specified.');
8500:
writeln ('No output file specified.');
goto 9000;
8700:
writeln ('Extension may not be specified on output file.');
9000:
end.